home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / doom / guide101.zip / SOURCE / WEAPONS.QC < prev    next >
Text File  |  1996-10-08  |  34KB  |  1,461 lines

  1.  /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25. };
  26.  
  27. void(entity me, entity camera)     SetViewPoint;
  28. void(entity me, vector viewangles) SetViewAngle;
  29.  
  30. float SVC_SETVIEWPORT = 5;    // Net.Protocol 0x05
  31. float SVC_SETVIEWANGLES = 10; // Net.Protocol 0x0A
  32. float SVC_UPDATEENTITY = 128; // Net.Protocol 0x80
  33.  
  34. void(entity me, entity camera) SetViewPoint =
  35. {
  36.   msg_entity = me;                         // target of message
  37.   WriteByte (MSG_ONE, SVC_SETVIEWPORT);    // 5 = SVC_SETVIEWPORT;  
  38.   WriteEntity (MSG_ONE, camera);           // view port
  39.   WriteByte (MSG_ONE, SVC_SETVIEWANGLES);  // 10 = SVC_SETVIEWANGLES
  40.   WriteAngle(MSG_ONE, camera.angles_x);    // tilt 
  41.   WriteAngle(MSG_ONE, camera.angles_y);    // yaw
  42.   WriteAngle(MSG_ONE, camera.angles_z);    // flip
  43. };
  44.  
  45. void(entity me, vector viewangles) SetViewAngle =
  46. {
  47.   msg_entity = me;                         // target of message
  48.   WriteByte(MSG_ONE, SVC_SETVIEWANGLES);   // 10 = SVC_SETVIEWANGLES
  49.   WriteAngle(MSG_ONE, viewangles_x);       // tilt 
  50.   WriteAngle(MSG_ONE, viewangles_y);       // yaw
  51.   WriteAngle(MSG_ONE, viewangles_z);       // flip
  52. };
  53.  
  54.  
  55. float() crandom =
  56. {
  57.     return 2*(random() - 0.5);
  58. };
  59.  
  60. /*
  61. ================
  62. W_FireAxe
  63. ================
  64. */
  65. void() W_FireAxe =
  66. {
  67.     local    vector    source;
  68.     local    vector    org;
  69.  
  70.     source = self.origin + '0 0 16';
  71.         traceline (source, source + v_forward*64, FALSE, self);
  72.     if (trace_fraction == 1.0)
  73.         return;
  74.     
  75.     org = trace_endpos - v_forward*4;
  76.  
  77.     if (trace_ent.takedamage)
  78.     {
  79.         trace_ent.axhitme = 1;
  80.         SpawnBlood (org, '0 0 0', 20);
  81.         T_Damage (trace_ent, self, self, 20);
  82.     }
  83.     else
  84.     {    // hit wall
  85.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  86.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  87.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  88.         WriteCoord (MSG_BROADCAST, org_x);
  89.         WriteCoord (MSG_BROADCAST, org_y);
  90.         WriteCoord (MSG_BROADCAST, org_z);
  91.     }
  92. };
  93.  
  94.  
  95. //============================================================================
  96.  
  97.  
  98. vector() wall_velocity =
  99. {
  100.     local vector    vel;
  101.     
  102.     vel = normalize (self.velocity);
  103.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  104.     vel = vel + 2*trace_plane_normal;
  105.     vel = vel * 200;
  106.     
  107.     return vel;
  108. };
  109.  
  110.  
  111. /*
  112. ================
  113. SpawnMeatSpray
  114. ================
  115. */
  116. void(vector org, vector vel) SpawnMeatSpray =
  117. {
  118.     local    entity missile, mpuff;
  119.     local    vector    org;
  120.  
  121.     missile = spawn ();
  122.     missile.owner = self;
  123.     missile.movetype = MOVETYPE_BOUNCE;
  124.     missile.solid = SOLID_NOT;
  125.  
  126.     makevectors (self.angles);
  127.  
  128.     missile.velocity = vel;
  129.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  130.  
  131.     missile.avelocity = '3000 1000 2000';
  132.     
  133. // set missile duration
  134.     missile.nextthink = time + 1;
  135.     missile.think = SUB_Remove;
  136.  
  137.     setmodel (missile, "progs/zom_gib.mdl");
  138.     setsize (missile, '0 0 0', '0 0 0');        
  139.     setorigin (missile, org);
  140. };
  141.  
  142. /*
  143. ================
  144. SpawnBlood
  145. ================
  146. */
  147. void(vector org, vector vel, float damage) SpawnBlood =
  148. {
  149.     particle (org, vel*0.1, 73, damage*2);
  150. };
  151.  
  152. /*
  153. ================
  154. spawn_touchblood
  155. ================
  156. */
  157. void(float damage) spawn_touchblood =
  158. {
  159.     local vector    vel;
  160.  
  161.     vel = wall_velocity () * 0.2;
  162.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  163. };
  164.  
  165.  
  166. /*
  167. ================
  168. SpawnChunk
  169. ================
  170. */
  171. void(vector org, vector vel) SpawnChunk =
  172. {
  173.     particle (org, vel*0.02, 0, 10);
  174. };
  175.  
  176. /*
  177. ==============================================================================
  178.  
  179. MULTI-DAMAGE
  180.  
  181. Collects multiple small damages into a single damage
  182.  
  183. ==============================================================================
  184. */
  185.  
  186. entity    multi_ent;
  187. float    multi_damage;
  188.  
  189. void() ClearMultiDamage =
  190. {
  191.     multi_ent = world;
  192.     multi_damage = 0;
  193. };
  194.  
  195. void() ApplyMultiDamage =
  196. {
  197.     if (!multi_ent)
  198.         return;
  199.     T_Damage (multi_ent, self, self, multi_damage);
  200. };
  201.  
  202. void(entity hit, float damage) AddMultiDamage =
  203. {
  204.     if (!hit)
  205.         return;
  206.     
  207.     if (hit != multi_ent)
  208.     {
  209.         ApplyMultiDamage ();
  210.         multi_damage = damage;
  211.         multi_ent = hit;
  212.     }
  213.     else
  214.         multi_damage = multi_damage + damage;
  215. };
  216.  
  217. /*
  218. ==============================================================================
  219.  
  220. BULLETS
  221.  
  222. ==============================================================================
  223. */
  224.  
  225. /*
  226. ================
  227. TraceAttack
  228. ================
  229. */
  230. void(float damage, vector dir) TraceAttack =
  231. {
  232.     local    vector    vel, org;
  233.     
  234.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  235.     vel = vel + 2*trace_plane_normal;
  236.     vel = vel * 200;
  237.  
  238.     org = trace_endpos - dir*4;
  239.  
  240.     if (trace_ent.takedamage)
  241.     {
  242.         SpawnBlood (org, vel*0.2, damage);
  243.         AddMultiDamage (trace_ent, damage);
  244.     }
  245.     else
  246.     {
  247.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  248.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  249.         WriteCoord (MSG_BROADCAST, org_x);
  250.         WriteCoord (MSG_BROADCAST, org_y);
  251.         WriteCoord (MSG_BROADCAST, org_z);
  252.     }
  253. };
  254.  
  255. /*
  256. ================
  257. FireBullets
  258.  
  259. Used by shotgun, super shotgun, and enemy soldier firing
  260. Go to the trouble of combining multiple pellets into a single damage call.
  261. ================
  262. */
  263. void(float shotcount, vector dir, vector spread) FireBullets =
  264. {
  265.     local    vector direction;
  266.     local    vector    src;
  267.     
  268.     makevectors(self.v_angle);
  269.  
  270.     src = self.origin + v_forward*10;
  271.     src_z = self.absmin_z + self.size_z * 0.7;
  272.  
  273.     ClearMultiDamage ();
  274.     while (shotcount > 0)
  275.     {
  276.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  277.  
  278.         traceline (src, src + direction*2048, FALSE, self);
  279.         if (trace_fraction != 1.0)
  280.             TraceAttack (4, direction);
  281.  
  282.         shotcount = shotcount - 1;
  283.     }
  284.     ApplyMultiDamage ();
  285. };
  286.  
  287. /*
  288. ================
  289. W_FireShotgun
  290. ================
  291. */
  292. void() W_FireShotgun =
  293. {
  294.     local vector dir;
  295.  
  296.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  297.  
  298.     self.punchangle_x = -2;
  299.     
  300.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  301.     dir = aim (self, 100000);
  302.     FireBullets (6, dir, '0.04 0.04 0');
  303. };
  304.  
  305.  
  306. /*
  307. ================
  308. W_FireSuperShotgun
  309. ================
  310. */
  311. void() W_FireSuperShotgun =
  312. {
  313.     local vector dir;
  314.  
  315.     if (self.currentammo == 1)
  316.     {
  317.         W_FireShotgun ();
  318.         return;
  319.     }
  320.         
  321.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  322.  
  323.     self.punchangle_x = -4;
  324.     
  325.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  326.     dir = aim (self, 100000);
  327.     FireBullets (14, dir, '0.14 0.08 0');
  328. };
  329.  
  330.  
  331. /*
  332. ==============================================================================
  333.  
  334. ROCKETS
  335.  
  336. ==============================================================================
  337. */
  338.  
  339. void()    s_explode1    =    [0,        s_explode2] {};
  340. void()    s_explode2    =    [1,        s_explode3] {};
  341. void()    s_explode3    =    [2,        s_explode4] {};
  342. void()    s_explode4    =    [3,        s_explode5] {};
  343. void()    s_explode5    =    [4,        s_explode6] {};
  344. void()    s_explode6    =    [5,        SUB_Remove] {};
  345.  
  346. void() BecomeExplosion =
  347. {
  348.     self.movetype = MOVETYPE_NONE;
  349.     self.velocity = '0 0 0';
  350.     self.touch = SUB_Null;
  351.     setmodel (self, "progs/s_explod.spr");
  352.     self.solid = SOLID_NOT;
  353.     s_explode1 ();
  354. };
  355.  
  356. void() T_MissileTouch =
  357. {
  358.     local float    damg;
  359.  
  360.     if (other == self.owner)
  361.         return;        // don't explode on owner
  362.  
  363.     if (pointcontents(self.origin) == CONTENT_SKY)
  364.     {
  365.         remove(self);
  366.         return;
  367.     }
  368.  
  369.     damg = 100 + random()*20;
  370.     
  371.     if (other.health)
  372.     {
  373.         if (other.classname == "monster_shambler")
  374.             damg = damg * 0.5;    // mostly immune
  375.         T_Damage (other, self, self.owner, damg );
  376.     }
  377.  
  378.     // don't do radius damage to the other, because all the damage
  379.     // was done in the impact
  380.     T_RadiusDamage (self, self.owner, 120, other);
  381.  
  382. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  383.     self.origin = self.origin - 8*normalize(self.velocity);
  384.  
  385.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  386.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  387.     WriteCoord (MSG_BROADCAST, self.origin_x);
  388.     WriteCoord (MSG_BROADCAST, self.origin_y);
  389.     WriteCoord (MSG_BROADCAST, self.origin_z);
  390.  
  391.     BecomeExplosion ();
  392. };
  393.  
  394.  
  395.  
  396. /*
  397. ================
  398. W_FireRocket
  399. ================
  400. */
  401. void() W_FireRocket =
  402. {
  403.     local    entity missile, mpuff;
  404.     
  405.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  406.     
  407.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  408.  
  409.     self.punchangle_x = -2;
  410.  
  411.     missile = spawn ();
  412.     missile.owner = self;
  413.     missile.movetype = MOVETYPE_FLYMISSILE;
  414.     missile.solid = SOLID_BBOX;
  415.         
  416. // set missile speed    
  417.  
  418.     makevectors (self.v_angle);
  419.     missile.velocity = aim(self, 1000);
  420.     missile.velocity = missile.velocity * 1000;
  421.     missile.angles = vectoangles(missile.velocity);
  422.     
  423.     missile.touch = T_MissileTouch;
  424.     
  425. // set missile duration
  426.     missile.nextthink = time + 5;
  427.     missile.think = SUB_Remove;
  428.  
  429.     setmodel (missile, "progs/missile.mdl");
  430.     setsize (missile, '0 0 0', '0 0 0');        
  431.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  432. };
  433.  
  434. //This section contains my guided missiles
  435. //I will comment them when I get around to it
  436.  
  437. void() PlayerDie;
  438. void() T_GMissileTouch;
  439. void() player_pain;
  440.  
  441. void() clone_pain =
  442. {
  443. T_Damage(self.owner,self,self,0);
  444. self.owner.dmg_take = self.dmg_take;
  445. self.owner.dmg_save = self.dmg_save;
  446. self.owner.dmg_inflictor = self.dmg_inflictor;
  447. self.owner.health = self.health;
  448. self.owner.armorvalue = self.armorvalue;
  449. self.owner.armortype = self.armortype;
  450. player_pain();
  451. };
  452.  
  453. void() CloneDie =
  454. {
  455. local entity    play;
  456.         play = self.owner;
  457.         self = play.mymissile;
  458.         other = world;
  459.         if (play.classname != "player") T_GMissileTouch();
  460.  
  461.         self = play;
  462.  
  463.         PlayerDie();
  464. };
  465.  
  466. void() T_GMissileTouch =
  467. {
  468. local float    damg;
  469.         if ((other == self.owner) /*|| (other == self.owner.clone)*/)
  470.         return;
  471.         if (other == self.owner.clone) other = self.owner;
  472.         self.owner.classname = "player";
  473.         self.owner.weaponmodel = self.owner.clone.weaponmodel;
  474.         self.owner.weaponframe = 0;
  475.         setmodel(self.owner, self.owner.clone.model);
  476.         self.owner.frame = self.owner.clone.frame;
  477.         self.owner.takedamage = DAMAGE_AIM;
  478.         self.owner.solid = SOLID_SLIDEBOX;
  479.         self.owner.view_ofs = '0 0 22';
  480.         setsize (self.owner, VEC_HULL_MIN, VEC_HULL_MAX);
  481.         self.owner.origin = self.owner.clone.origin;
  482.         self.owner.velocity = self.owner.clone.velocity;
  483.         self.owner.armorvalue = self.owner.clone.armorvalue;
  484.         self.owner.armortype = self.owner.clone.armortype;
  485.         self.owner.v_angle = self.owner.clone.v_angle;
  486.         self.owner.angles = self.owner.clone.angles;
  487.         self.owner.health = self.owner.clone.health;
  488.         self.owner.flags = self.owner.clone.flags;
  489.         self.owner.flags = self.owner.flags - (self.owner.flags & FL_NOTARGET);
  490.         self.owner.invisible_time = self.owner.clone.invisible_time;
  491.         self.owner.invisible_finished = self.owner.clone.invisible_finished;
  492.         self.owner.invincible_time = self.owner.clone.invincible_time;
  493.         self.owner.invincible_finished = self.owner.clone.invincible_finished;
  494.         self.owner.super_time = self.owner.clone.super_time;
  495.         self.owner.super_damage_finished = self.owner.clone.super_damage_finished;
  496.         self.owner.rad_time = self.owner.clone.rad_time;
  497.         self.owner.radsuit_finished = self.owner.clone.radsuit_finished;
  498.         self.owner.waterlevel = 0;
  499.         self.owner.watertype = self.owner.clone.watertype;
  500.         SetViewAngle(self.owner,self.owner.clone.v_angle);
  501.         setmodel(self.owner.clone,"");
  502.         self.owner.clone.solid = SOLID_NOT;
  503.         self.owner.clone.takedamage = DAMAGE_NO;
  504.         damg = 50 + random()*50;
  505.     if (other.health)
  506.     {
  507.         if (other.classname == "monster_shambler")
  508.             damg = damg * 0.5;    // mostly immune
  509.     }
  510.     T_Damage (other, self, self.owner, damg );
  511.         T_RadiusDamage (self, self.owner, 90, other);
  512.  
  513.     if (pointcontents(self.origin) == CONTENT_SKY)
  514.     {
  515.         remove(self);
  516.         return;
  517.     }
  518.     
  519.  
  520.         sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  521.     self.origin = self.origin - 8*normalize(self.velocity);
  522.  
  523.         BecomeExplosion ();
  524.  
  525. };
  526.  
  527.  
  528.  
  529. /*
  530. ================
  531. W_FireRocket
  532. ================
  533. */
  534. void() GuideThink;
  535.  
  536. void() W_FireMissile =
  537. {
  538.     local    entity missile, mpuff;
  539.     
  540.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  541.     
  542.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  543.  
  544.     self.punchangle_x = -2;
  545.  
  546.     missile = spawn ();
  547.     missile.owner = self;
  548.         missile.movetype = MOVETYPE_FLY;//MISSILE;
  549.     missile.solid = SOLID_BBOX;
  550.         
  551. // set missile speed    
  552.  
  553.     makevectors (self.v_angle);
  554.     missile.velocity = aim(self, 1000);
  555.         missile.velocity = missile.velocity * 350;
  556.     missile.angles = vectoangles(missile.velocity);
  557.     
  558.         missile.touch = T_GMissileTouch;
  559.     
  560.         missile.nextthink = time + 0.01;
  561.         missile.think = GuideThink; 
  562.         self.clone.armorvalue = self.armorvalue;
  563.         self.clone.armortype = self.armortype;
  564.         self.clone.health = 100;
  565.         self.flags = (self.flags | FL_NOTARGET);
  566.         self.flags = self.flags - (self.flags & FL_ONGROUND);
  567.         self.clone.origin = self.origin;
  568.         self.clone.angles = self.angles;
  569.         self.clone.v_angle = self.v_angle;
  570.         setmodel(self.clone,self.model);
  571.         self.clone.frame = self.frame;
  572.         self.clone.takedamage = DAMAGE_AIM;
  573.         self.clone.health = self.health;
  574.         self.clone.max_health = self.max_health;
  575.         self.clone.solid = SOLID_SLIDEBOX;
  576.         self.clone.weaponmodel = self.weaponmodel;
  577.         self.clone.th_pain = clone_pain;
  578.         self.clone.th_die = CloneDie;
  579.         self.clone.colormap = self.colormap;
  580.         self.clone.skin = self.skin;
  581.         self.clone.weapon = self.weapon;
  582.         self.clone.movetype = MOVETYPE_STEP;
  583.         self.clone.velocity = self.velocity;
  584.         self.clone.nextthink = self.nextthink;
  585.         self.clone.think = self.think;
  586.         self.clone.effects = self.effects | EF_DIMLIGHT;
  587.         self.clone.flags = self.flags;
  588.         self.clone.waterlevel = self.waterlevel;
  589.         self.clone.watertype = self.watertype;
  590.         self.clone.invisible_time = self.invisible_time;
  591.         self.clone.invisible_finished = self.invisible_finished;
  592.         self.clone.invincible_time = self.invincible_time;
  593.         self.clone.invincible_finished = self.invincible_finished;
  594.         self.clone.super_time = self.super_time;
  595.         self.clone.super_damage_finished = self.super_damage_finished;
  596.         self.clone.rad_time = self.rad_time;
  597.         self.clone.radsuit_finished = self.radsuit_finished;
  598.         setsize (self.clone, VEC_HULL_MIN, VEC_HULL_MAX);
  599.         setmodel (missile, "progs/missile.mdl");
  600.     setsize (missile, '0 0 0', '0 0 0');        
  601.         setorigin (missile, self.origin + v_forward*24 + '0 0 16');
  602.         setmodel(self, "");
  603.         setsize(self, '0 0 0', '0 0 0');
  604.         self.solid = SOLID_NOT;
  605.         self.view_ofs = '0 0 0';
  606.         self.weaponmodel = "";
  607.         missile.classname = "gmissile";
  608.         self.classname = "gplayer";
  609.         self.mymissile = missile;
  610. };
  611.  
  612. void() CheckPowerups;
  613.  
  614. void() GuideThink =
  615. {          
  616.         local entity temp;
  617.         temp = self;
  618.         self = self.owner.clone;
  619.         droptofloor();
  620.         self = temp;
  621.         self.angles = self.owner.v_angle;
  622.         makevectors(self.angles);
  623.         self.velocity = normalize(v_forward) * (300);
  624.         self.angles_x = 0-self.angles_x;
  625.         makevectors(self.angles);
  626.         self.owner.origin = self.origin - normalize(v_forward)*5;
  627.         self.owner.velocity = '0 0 0';
  628.         self.nextthink = time + 0.01;
  629.         self.think = GuideThink;
  630.         if (self.owner.button2) {
  631.                 if ( !(self.owner.flags & FL_JUMPRELEASED) )
  632.                         return;         // don't pogo stick
  633.                 self.owner.clone.flags = self.owner.clone.flags-(self.owner.clone.flags&(FL_JUMPRELEASED));
  634.                 self.owner.button2 = 0;
  635.                 other = world;
  636.                 T_GMissileTouch();
  637.                 } else self.owner.flags = self.owner.flags|FL_JUMPRELEASED;
  638. };
  639.  
  640. /*
  641. ===============================================================================
  642.  
  643. LIGHTNING
  644.  
  645. ===============================================================================
  646. */
  647.  
  648. /*
  649. =================
  650. LightningDamage
  651. =================
  652. */
  653. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  654. {
  655.     local entity        e1, e2;
  656.     local vector        f;
  657.     
  658.     f = p2 - p1;
  659.     normalize (f);
  660.     f_x = 0 - f_y;
  661.     f_y = f_x;
  662.     f_z = 0;
  663.     f = f*16;
  664.  
  665.     e1 = e2 = world;
  666.  
  667.     traceline (p1, p2, FALSE, self);
  668.     if (trace_ent.takedamage)
  669.     {
  670.         particle (trace_endpos, '0 0 100', 225, damage*4);
  671.         T_Damage (trace_ent, from, from, damage);
  672.         if (self.classname == "player")
  673.         {
  674.             if (other.classname == "player")
  675.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  676.         }
  677.     }
  678.     e1 = trace_ent;
  679.  
  680.     traceline (p1 + f, p2 + f, FALSE, self);
  681.     if (trace_ent != e1 && trace_ent.takedamage)
  682.     {
  683.         particle (trace_endpos, '0 0 100', 225, damage*4);
  684.         T_Damage (trace_ent, from, from, damage);
  685.     }
  686.     e2 = trace_ent;
  687.  
  688.     traceline (p1 - f, p2 - f, FALSE, self);
  689.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  690.     {
  691.         particle (trace_endpos, '0 0 100', 225, damage*4);
  692.         T_Damage (trace_ent, from, from, damage);
  693.     }
  694. };
  695.  
  696.  
  697. void() W_FireLightning =
  698. {
  699.     local    vector        org;
  700.  
  701.     if (self.ammo_cells < 1)
  702.     {
  703.         self.weapon = W_BestWeapon ();
  704.         W_SetCurrentAmmo ();
  705.         return;
  706.     }
  707.  
  708. // explode if under water
  709.     if (self.waterlevel > 1)
  710.     {
  711.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  712.         self.ammo_cells = 0;
  713.         W_SetCurrentAmmo ();
  714.         return;
  715.     }
  716.  
  717.     if (self.t_width < time)
  718.     {
  719.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  720.         self.t_width = time + 0.6;
  721.     }
  722.     self.punchangle_x = -2;
  723.  
  724.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  725.  
  726.     org = self.origin + '0 0 16';
  727.     
  728.     traceline (org, org + v_forward*600, TRUE, self);
  729.  
  730.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  731.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  732.     WriteEntity (MSG_BROADCAST, self);
  733.     WriteCoord (MSG_BROADCAST, org_x);
  734.     WriteCoord (MSG_BROADCAST, org_y);
  735.     WriteCoord (MSG_BROADCAST, org_z);
  736.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  737.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  738.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  739.  
  740.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  741. };
  742.  
  743.  
  744. //=============================================================================
  745.  
  746.  
  747. void() GrenadeExplode =
  748. {
  749.     T_RadiusDamage (self, self.owner, 120, world);
  750.  
  751.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  752.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  753.     WriteCoord (MSG_BROADCAST, self.origin_x);
  754.     WriteCoord (MSG_BROADCAST, self.origin_y);
  755.     WriteCoord (MSG_BROADCAST, self.origin_z);
  756.  
  757.     BecomeExplosion ();
  758. };
  759.  
  760. void() GrenadeTouch =
  761. {
  762.     if (other == self.owner)
  763.         return;        // don't explode on owner
  764.     if (other.takedamage == DAMAGE_AIM)
  765.     {
  766.         GrenadeExplode();
  767.         return;
  768.     }
  769.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  770.     if (self.velocity == '0 0 0')
  771.         self.avelocity = '0 0 0';
  772. };
  773.  
  774. /*
  775. ================
  776. W_FireGrenade
  777. ================
  778. */
  779. void() W_FireGrenade =
  780. {
  781.     local    entity missile, mpuff;
  782.     
  783.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  784.     
  785.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  786.  
  787.     self.punchangle_x = -2;
  788.  
  789.     missile = spawn ();
  790.     missile.owner = self;
  791.     missile.movetype = MOVETYPE_BOUNCE;
  792.     missile.solid = SOLID_BBOX;
  793.     missile.classname = "grenade";
  794.         
  795. // set missile speed    
  796.  
  797.     makevectors (self.v_angle);
  798.  
  799.     if (self.v_angle_x)
  800.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  801.     else
  802.     {
  803.         missile.velocity = aim(self, 10000);
  804.         missile.velocity = missile.velocity * 600;
  805.         missile.velocity_z = 200;
  806.     }
  807.  
  808.     missile.avelocity = '300 300 300';
  809.  
  810.     missile.angles = vectoangles(missile.velocity);
  811.     
  812.     missile.touch = GrenadeTouch;
  813.     
  814. // set missile duration
  815.     missile.nextthink = time + 2.5;
  816.     missile.think = GrenadeExplode;
  817.  
  818.     setmodel (missile, "progs/grenade.mdl");
  819.     setsize (missile, '0 0 0', '0 0 0');        
  820.     setorigin (missile, self.origin);
  821. };
  822.  
  823.  
  824. //=============================================================================
  825.  
  826. void() spike_touch;
  827. void() superspike_touch;
  828.  
  829.  
  830. /*
  831. ===============
  832. launch_spike
  833.  
  834. Used for both the player and the ogre
  835. ===============
  836. */
  837. void(vector org, vector dir) launch_spike =
  838. {
  839.     newmis = spawn ();
  840.     newmis.owner = self;
  841.     newmis.movetype = MOVETYPE_FLYMISSILE;
  842.     newmis.solid = SOLID_BBOX;
  843.  
  844.     newmis.angles = vectoangles(dir);
  845.     
  846.     newmis.touch = spike_touch;
  847.     newmis.classname = "spike";
  848.     newmis.think = SUB_Remove;
  849.     newmis.nextthink = time + 6;
  850.     setmodel (newmis, "progs/spike.mdl");
  851.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  852.     setorigin (newmis, org);
  853.  
  854.     newmis.velocity = dir * 1000;
  855. };
  856.  
  857. void() W_FireSuperSpikes =
  858. {
  859.     local vector    dir;
  860.     local entity    old;
  861.     
  862.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  863.     self.attack_finished = time + 0.2;
  864.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  865.     dir = aim (self, 1000);
  866.     launch_spike (self.origin + '0 0 16', dir);
  867.     newmis.touch = superspike_touch;
  868.     setmodel (newmis, "progs/s_spike.mdl");
  869.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  870.     self.punchangle_x = -2;
  871. };
  872.  
  873. void(float ox) W_FireSpikes =
  874. {
  875.     local vector    dir;
  876.     local entity    old;
  877.     
  878.     makevectors (self.v_angle);
  879.     
  880.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  881.     {
  882.         W_FireSuperSpikes ();
  883.         return;
  884.     }
  885.  
  886.     if (self.ammo_nails < 1)
  887.     {
  888.         self.weapon = W_BestWeapon ();
  889.         W_SetCurrentAmmo ();
  890.         return;
  891.     }
  892.  
  893.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  894.     self.attack_finished = time + 0.2;
  895.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  896.     dir = aim (self, 1000);
  897.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  898.  
  899.     self.punchangle_x = -2;
  900. };
  901.  
  902.  
  903.  
  904. .float hit_z;
  905. void() spike_touch =
  906. {
  907. local float rand;
  908.     if (other == self.owner)
  909.         return;
  910.  
  911.     if (other.solid == SOLID_TRIGGER)
  912.         return;    // trigger field, do nothing
  913.  
  914.     if (pointcontents(self.origin) == CONTENT_SKY)
  915.     {
  916.         remove(self);
  917.         return;
  918.     }
  919.     
  920. // hit something that bleeds
  921.     if (other.takedamage)
  922.     {
  923.         spawn_touchblood (9);
  924.         T_Damage (other, self, self.owner, 9);
  925.     }
  926.     else
  927.     {
  928.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  929.         
  930.         if (self.classname == "wizspike")
  931.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  932.         else if (self.classname == "knightspike")
  933.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  934.         else
  935.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  936.         WriteCoord (MSG_BROADCAST, self.origin_x);
  937.         WriteCoord (MSG_BROADCAST, self.origin_y);
  938.         WriteCoord (MSG_BROADCAST, self.origin_z);
  939.     }
  940.  
  941.     remove(self);
  942.  
  943. };
  944.  
  945. void() superspike_touch =
  946. {
  947. local float rand;
  948.     if (other == self.owner)
  949.         return;
  950.  
  951.     if (other.solid == SOLID_TRIGGER)
  952.         return;    // trigger field, do nothing
  953.  
  954.     if (pointcontents(self.origin) == CONTENT_SKY)
  955.     {
  956.         remove(self);
  957.         return;
  958.     }
  959.     
  960. // hit something that bleeds
  961.     if (other.takedamage)
  962.     {
  963.         spawn_touchblood (18);
  964.         T_Damage (other, self, self.owner, 18);
  965.     }
  966.     else
  967.     {
  968.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  969.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  970.         WriteCoord (MSG_BROADCAST, self.origin_x);
  971.         WriteCoord (MSG_BROADCAST, self.origin_y);
  972.         WriteCoord (MSG_BROADCAST, self.origin_z);
  973.     }
  974.  
  975.     remove(self);
  976.  
  977. };
  978.  
  979.  
  980. /*
  981. ===============================================================================
  982.  
  983. PLAYER WEAPON USE
  984.  
  985. ===============================================================================
  986. */
  987.  
  988. void() W_SetCurrentAmmo =
  989. {
  990.     player_run ();        // get out of any weapon firing states
  991.  
  992.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  993.     
  994.     if (self.weapon == IT_AXE)
  995.     {
  996.         self.currentammo = 0;
  997.         self.weaponmodel = "progs/v_axe.mdl";
  998.         self.weaponframe = 0;
  999.     }
  1000.     else if (self.weapon == IT_SHOTGUN)
  1001.     {
  1002.         self.currentammo = self.ammo_shells;
  1003.         self.weaponmodel = "progs/v_shot.mdl";
  1004.         self.weaponframe = 0;
  1005.         self.items = self.items | IT_SHELLS;
  1006.     }
  1007.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1008.     {
  1009.         self.currentammo = self.ammo_shells;
  1010.         self.weaponmodel = "progs/v_shot2.mdl";
  1011.         self.weaponframe = 0;
  1012.         self.items = self.items | IT_SHELLS;
  1013.     }
  1014.     else if (self.weapon == IT_NAILGUN)
  1015.     {
  1016.         self.currentammo = self.ammo_nails;
  1017.         self.weaponmodel = "progs/v_nail.mdl";
  1018.         self.weaponframe = 0;
  1019.         self.items = self.items | IT_NAILS;
  1020.     }
  1021.     else if (self.weapon == IT_SUPER_NAILGUN)
  1022.     {
  1023.         self.currentammo = self.ammo_nails;
  1024.         self.weaponmodel = "progs/v_nail2.mdl";
  1025.         self.weaponframe = 0;
  1026.         self.items = self.items | IT_NAILS;
  1027.     }
  1028.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1029.     {
  1030.         self.currentammo = self.ammo_rockets;
  1031.         self.weaponmodel = "progs/v_rock.mdl";
  1032.         self.weaponframe = 0;
  1033.         self.items = self.items | IT_ROCKETS;
  1034.     }
  1035.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1036.     {
  1037.         self.currentammo = self.ammo_rockets;
  1038.         self.weaponmodel = "progs/v_rock2.mdl";
  1039.         self.weaponframe = 0;
  1040.         self.items = self.items | IT_ROCKETS;
  1041.     }
  1042.     else if (self.weapon == IT_LIGHTNING)
  1043.     {
  1044.         self.currentammo = self.ammo_cells;
  1045.         self.weaponmodel = "progs/v_light.mdl";
  1046.         self.weaponframe = 0;
  1047.         self.items = self.items | IT_CELLS;
  1048.     }
  1049.     else
  1050.     {
  1051.         self.currentammo = 0;
  1052.         self.weaponmodel = "";
  1053.         self.weaponframe = 0;
  1054.     }
  1055. };
  1056.  
  1057. float() W_BestWeapon =
  1058. {
  1059.     local    float    it;
  1060.     
  1061.     it = self.items;
  1062.  
  1063.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  1064.         return IT_LIGHTNING;
  1065.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  1066.         return IT_SUPER_NAILGUN;
  1067.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  1068.         return IT_SUPER_SHOTGUN;
  1069.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  1070.         return IT_NAILGUN;
  1071.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  1072.         return IT_SHOTGUN;
  1073.         
  1074. /*
  1075.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  1076.         return IT_ROCKET_LAUNCHER;
  1077.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  1078.         return IT_GRENADE_LAUNCHER;
  1079.  
  1080. */
  1081.  
  1082.     return IT_AXE;
  1083. };
  1084.  
  1085. float() W_CheckNoAmmo =
  1086. {
  1087.     if (self.currentammo > 0)
  1088.         return TRUE;
  1089.  
  1090.     if (self.weapon == IT_AXE)
  1091.         return TRUE;
  1092.     
  1093.     self.weapon = W_BestWeapon ();
  1094.  
  1095.     W_SetCurrentAmmo ();
  1096.     
  1097. // drop the weapon down
  1098.     return FALSE;
  1099. };
  1100.  
  1101. /*
  1102. ============
  1103. W_Attack
  1104.  
  1105. An attack impulse can be triggered now
  1106. ============
  1107. */
  1108. void()    player_axe1;
  1109. void()    player_axeb1;
  1110. void()    player_axec1;
  1111. void()    player_axed1;
  1112. void()    player_shot1;
  1113. void()    player_nail1;
  1114. void()    player_light1;
  1115. void()    player_rocket1;
  1116.  
  1117. void() W_Attack =
  1118. {
  1119.     local    float    r;
  1120.  
  1121.     if (!W_CheckNoAmmo ())
  1122.         return;
  1123.  
  1124.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  1125.     self.show_hostile = time + 1;    // wake monsters up
  1126.  
  1127.     if (self.weapon == IT_AXE)
  1128.     {
  1129.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  1130.         r = random();
  1131.         if (r < 0.25)
  1132.             player_axe1 ();
  1133.         else if (r<0.5)
  1134.             player_axeb1 ();
  1135.         else if (r<0.75)
  1136.             player_axec1 ();
  1137.         else
  1138.             player_axed1 ();
  1139.         self.attack_finished = time + 0.5;
  1140.     }
  1141.     else if (self.weapon == IT_SHOTGUN)
  1142.     {
  1143.         player_shot1 ();
  1144.         W_FireShotgun ();
  1145.         self.attack_finished = time + 0.5;
  1146.     }
  1147.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1148.     {
  1149.         player_shot1 ();
  1150.         W_FireSuperShotgun ();
  1151.         self.attack_finished = time + 0.7;
  1152.     }
  1153.     else if (self.weapon == IT_NAILGUN)
  1154.     {
  1155.         player_nail1 ();
  1156.     }
  1157.     else if (self.weapon == IT_SUPER_NAILGUN)
  1158.     {
  1159.         player_nail1 ();
  1160.     }
  1161.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1162.     {
  1163.         player_rocket1();
  1164.         W_FireGrenade();
  1165.         self.attack_finished = time + 0.6;
  1166.     }
  1167.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1168.     {
  1169.                    player_rocket1();
  1170.                    if (self.missiletype == 0) W_FireRocket();
  1171.                    else W_FireMissile();
  1172.                    self.attack_finished = time + 0.8;
  1173.     }
  1174.     else if (self.weapon == IT_LIGHTNING)
  1175.     {
  1176.         player_light1();
  1177.         self.attack_finished = time + 0.1;
  1178.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1179.     }
  1180. };
  1181.  
  1182. /*
  1183. ============
  1184. W_ChangeWeapon
  1185.  
  1186. ============
  1187. */
  1188. void() W_ChangeWeapon =
  1189. {
  1190.     local    float    it, am, fl;
  1191.     
  1192.     it = self.items;
  1193.     am = 0;
  1194.     
  1195.     if (self.impulse == 1)
  1196.     {
  1197.         fl = IT_AXE;
  1198.     }
  1199.     else if (self.impulse == 2)
  1200.     {
  1201.         fl = IT_SHOTGUN;
  1202.         if (self.ammo_shells < 1)
  1203.             am = 1;
  1204.     }
  1205.     else if (self.impulse == 3)
  1206.     {
  1207.         fl = IT_SUPER_SHOTGUN;
  1208.         if (self.ammo_shells < 2)
  1209.             am = 1;
  1210.     }        
  1211.     else if (self.impulse == 4)
  1212.     {
  1213.         fl = IT_NAILGUN;
  1214.         if (self.ammo_nails < 1)
  1215.             am = 1;
  1216.     }
  1217.     else if (self.impulse == 5)
  1218.     {
  1219.         fl = IT_SUPER_NAILGUN;
  1220.         if (self.ammo_nails < 2)
  1221.             am = 1;
  1222.     }
  1223.     else if (self.impulse == 6)
  1224.     {
  1225.         fl = IT_GRENADE_LAUNCHER;
  1226.         if (self.ammo_rockets < 1)
  1227.             am = 1;
  1228.     }
  1229.     else if (self.impulse == 7)
  1230.     {
  1231.         fl = IT_ROCKET_LAUNCHER;
  1232.                 if (self.weapon == IT_ROCKET_LAUNCHER) self.missiletype = self.missiletype + 1;
  1233.                 if (self.missiletype == 2) self.missiletype = 0;
  1234.                 if (self.missiletype == 0) sprint(self,"Regular missiles\n");
  1235.                         else sprint(self,"Guided missiles!\n");
  1236.         if (self.ammo_rockets < 1)
  1237.             am = 1;
  1238.     }
  1239.     else if (self.impulse == 8)
  1240.     {
  1241.         fl = IT_LIGHTNING;
  1242.         if (self.ammo_cells < 1)
  1243.             am = 1;
  1244.     }
  1245.  
  1246.     self.impulse = 0;
  1247.     
  1248.     if (!(self.items & fl))
  1249.     {    // don't have the weapon or the ammo
  1250.         sprint (self, "no weapon.\n");
  1251.         return;
  1252.     }
  1253.     
  1254.     if (am)
  1255.     {    // don't have the ammo
  1256.         sprint (self, "not enough ammo.\n");
  1257.         return;
  1258.     }
  1259.  
  1260. //
  1261. // set weapon, set ammo
  1262. //
  1263.     self.weapon = fl;        
  1264.     W_SetCurrentAmmo ();
  1265. };
  1266.  
  1267. /*
  1268. ============
  1269. CheatCommand
  1270. ============
  1271. */
  1272. void() CheatCommand =
  1273. {
  1274. //        if (deathmatch)
  1275. //                return;
  1276.  
  1277.     self.ammo_rockets = 100;
  1278.     self.ammo_nails = 200;
  1279.     self.ammo_shells = 100;
  1280.     self.items = self.items | 
  1281.         IT_AXE |
  1282.         IT_SHOTGUN |
  1283.         IT_SUPER_SHOTGUN |
  1284.         IT_NAILGUN |
  1285.         IT_SUPER_NAILGUN |
  1286.         IT_GRENADE_LAUNCHER |
  1287.         IT_ROCKET_LAUNCHER |
  1288.         IT_KEY1 | IT_KEY2;
  1289.  
  1290.     self.ammo_cells = 200;
  1291.     self.items = self.items | IT_LIGHTNING;
  1292.  
  1293.     self.weapon = IT_ROCKET_LAUNCHER;
  1294.     self.impulse = 0;
  1295.     W_SetCurrentAmmo ();
  1296. };
  1297.  
  1298. /*
  1299. ============
  1300. CycleWeaponCommand
  1301.  
  1302. Go to the next weapon with ammo
  1303. ============
  1304. */
  1305. void() CycleWeaponCommand =
  1306. {
  1307.     local    float    it, am;
  1308.     
  1309.     it = self.items;
  1310.     self.impulse = 0;
  1311.     
  1312.     while (1)
  1313.     {
  1314.         am = 0;
  1315.  
  1316.         if (self.weapon == IT_LIGHTNING)
  1317.         {
  1318.             self.weapon = IT_AXE;
  1319.         }
  1320.         else if (self.weapon == IT_AXE)
  1321.         {
  1322.             self.weapon = IT_SHOTGUN;
  1323.             if (self.ammo_shells < 1)
  1324.                 am = 1;
  1325.         }
  1326.         else if (self.weapon == IT_SHOTGUN)
  1327.         {
  1328.             self.weapon = IT_SUPER_SHOTGUN;
  1329.             if (self.ammo_shells < 2)
  1330.                 am = 1;
  1331.         }        
  1332.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1333.         {
  1334.             self.weapon = IT_NAILGUN;
  1335.             if (self.ammo_nails < 1)
  1336.                 am = 1;
  1337.         }
  1338.         else if (self.weapon == IT_NAILGUN)
  1339.         {
  1340.             self.weapon = IT_SUPER_NAILGUN;
  1341.             if (self.ammo_nails < 2)
  1342.                 am = 1;
  1343.         }
  1344.         else if (self.weapon == IT_SUPER_NAILGUN)
  1345.         {
  1346.             self.weapon = IT_GRENADE_LAUNCHER;
  1347.             if (self.ammo_rockets < 1)
  1348.                 am = 1;
  1349.         }
  1350.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1351.         {
  1352.             self.weapon = IT_ROCKET_LAUNCHER;
  1353.             if (self.ammo_rockets < 1)
  1354.                 am = 1;
  1355.         }
  1356.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1357.         {
  1358.             self.weapon = IT_LIGHTNING;
  1359.             if (self.ammo_cells < 1)
  1360.                 am = 1;
  1361.         }
  1362.     
  1363.         if ( (self.items & self.weapon) && am == 0)
  1364.         {
  1365.             W_SetCurrentAmmo ();
  1366.             return;
  1367.         }
  1368.     }
  1369.  
  1370. };
  1371.  
  1372. /*
  1373. ============
  1374. ServerflagsCommand
  1375.  
  1376. Just for development
  1377. ============
  1378. */
  1379. void() ServerflagsCommand =
  1380. {
  1381.     serverflags = serverflags * 2 + 1;
  1382. };
  1383.  
  1384. void() QuadCheat =
  1385. {
  1386.     if (deathmatch || coop)
  1387.         return;
  1388.     self.super_time = 1;
  1389.     self.super_damage_finished = time + 30;
  1390.     self.items = self.items | IT_QUAD;
  1391.     dprint ("quad cheat\n");
  1392. };
  1393.  
  1394. /*
  1395. ============
  1396. ImpulseCommands
  1397.  
  1398. ============
  1399. */
  1400. void() ImpulseCommands =
  1401. {
  1402.     if (self.impulse >= 1 && self.impulse <= 8)
  1403.         W_ChangeWeapon ();
  1404.  
  1405.     if (self.impulse == 9)
  1406.         CheatCommand ();
  1407.     if (self.impulse == 10)
  1408.         CycleWeaponCommand ();
  1409.     if (self.impulse == 11)
  1410.         ServerflagsCommand ();
  1411.  
  1412.     if (self.impulse == 255)
  1413.         QuadCheat ();
  1414.         
  1415.     self.impulse = 0;
  1416. };
  1417.  
  1418. /*
  1419. ============
  1420. W_WeaponFrame
  1421.  
  1422. Called every frame so impulse events can be handled as well as possible
  1423. ============
  1424. */
  1425. void() W_WeaponFrame =
  1426. {
  1427.     if (time < self.attack_finished)
  1428.         return;
  1429.  
  1430.     ImpulseCommands ();
  1431.     
  1432. // check for attack
  1433.     if (self.button0)
  1434.     {
  1435.         SuperDamageSound ();
  1436.         W_Attack ();
  1437.     }
  1438. };
  1439.  
  1440. /*
  1441. ========
  1442. SuperDamageSound
  1443.  
  1444. Plays sound if needed
  1445. ========
  1446. */
  1447. void() SuperDamageSound =
  1448. {
  1449.     if (self.super_damage_finished > time)
  1450.     {
  1451.         if (self.super_sound < time)
  1452.         {
  1453.             self.super_sound = time + 1;
  1454.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1455.         }
  1456.     }
  1457.     return;
  1458. };
  1459.  
  1460.  
  1461.